//
//  SwitcherTool.m
//  BalanceCar
//
//  Created by 郑信鸿 on 2017/9/14.
//  Copyright © 2017年 郑信鸿. All rights reserved.
//

#import "SwitcherTool.h"

@implementation SwitcherTool

+ (SwitcherTool *)shareManager
{
    static SwitcherTool *managerInstance = nil;
    static dispatch_once_t token;
    dispatch_once(&token, ^{
        managerInstance = [[self alloc] init];
    });
    return managerInstance;
}

- (instancetype)init{
    
    if (self = [super init]) {
        
        self.kmOrMile = [[NSUserDefaults standardUserDefaults] boolForKey:@"kmOrMile"];
    }
    return self;
}

- (void)setKmOrMile:(BOOL)kmOrMile{
    _kmOrMile = kmOrMile;
    [[NSUserDefaults standardUserDefaults] setBool:kmOrMile forKey:@"kmOrMile"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

- (NSString *)unit{
    
    if (!_kmOrMile) {
        
        return @"km";
    }else{
        return @"mile";
    }
    
}

- (float)rate{
    
    if (!_kmOrMile) {
        
        return 1.0;
        
    }else{
        
        return 0.6213712;
    }
    
}

@end
